package com.base.andlanggl.objects

import com.base.andlanggl.data.VertexArray
import com.base.andlanggl.programs.TextureShaderProgram
import android.opengl.GLES20.*

class Table {
    companion object{
        const val POSITION_COMPONENT_COUNT:Int=2 //xy坐标计数
        const val TEXTURE_COORDINATES_COMPONENT_COUNT:Int=2 //st纹理坐标计数
        const val STRIDE:Int= (POSITION_COMPONENT_COUNT + TEXTURE_COORDINATES_COMPONENT_COUNT)* VertexArray.BYTES_PER_FLOAT //步长
        val VERTEX_DATA:FloatArray=floatArrayOf(
            //X, Y, S, T
            0f,    0f, 0.5f, 0.5f,
            -0.5f, -0.8f,   0f, 0.9f,
            0.5f, -0.8f,   1f, 0.9f,
            0.5f,  0.8f,   1f, 0.1f,
            -0.5f,  0.8f,   0f, 0.1f,
            -0.5f, -0.8f,   0f, 0.9f
        )
    }
    var vertexArray:VertexArray= VertexArray(VERTEX_DATA)

    fun bindData(textureProgram:TextureShaderProgram){
        vertexArray.setVertexAttribPointer(0,textureProgram.aPositionLocation,POSITION_COMPONENT_COUNT, STRIDE)
        vertexArray.setVertexAttribPointer(POSITION_COMPONENT_COUNT,textureProgram.aTextureCoordinatesLocation,TEXTURE_COORDINATES_COMPONENT_COUNT,
            STRIDE)
    }

    fun draw(){
        glDrawArrays(GL_TRIANGLE_FAN,0,6)
    }
}